﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace XML_Creator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog OFD = new OpenFileDialog();

            if (OFD.ShowDialog() == DialogResult.OK)
            {
                StreamReader SR = new StreamReader(OFD.FileName);

                var id = SR.ReadToEnd().Split('\n');
                SR.Close();

                label2.Text = id.Count().ToString();
                MakeXML(id);
                label2.Text = id.Count().ToString() + " Saved";
                
            }
        }

        private void MakeXML(string[] id)
        {
            var writer = new XmlTextWriter(@"e:/block.xml",Encoding.Default);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 4;

            writer.WriteStartElement("Blocks");
            
            for (int a = 0; a < id.Length-1; a++)
            {
                
                writer.WriteStartElement(id[a], null);
                

                for (int i = 0; i < xmlElementAtrib.Length; i++)
                {
                    writer.WriteElementString(xmlElementAtrib[i], "null");
                   
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.Close();

        }

        private string[] xmlElementAtrib =
                    {
                       
                        "FaceFront",
                        "FaceTop",
                        "FaceBottom",
                        "FaceLeft",
                        "FaceRight",
                        "FaceBack",
                        "CubeType",
                    };
    }

    
}
